<?php
/**
 * 成交凭证模型
 */
namespace app\common\model;
use think\model\concern\SoftDelete;
class Deal extends \think\Model{
    protected $resultSetType = 'collection';
    use SoftDelete;
    protected $deleteTime = 'delete_time';

    /**
     * 上传成交凭证文件
     * @param string file 提交文件名
     * @param int message_id 用户ID
     * @return array 返回信息
     */
    public function inserts(){
        $data = input('param.');
        if (!$data['message_id'])
            return [
                'message' => 'message_id不能为空'
            ];

        $URL = "./static/upload/deal/";
        //上传文件
        $upload = new \app\common\logic\Upload();
        $pathName = $upload -> img('file',$URL);
        $dealImg =new \app\common\model\Deal();
        $saveData = [];
        foreach ($pathName as $k=> $value){
            $pathName[$k] = ltrim($value,'.');
            $saveData[] = [
                'message_id' => $data['message_id'],
                'img' => $pathName[$k],
                'date' => time(),
            ];
        }
        $dealImg -> insertAll($saveData);

        $info = $this -> where('message_id',$data['message_id'])->select();

        return json([
            'code' => '1',
            'message' => '上传成功',
            'pathName' => $pathName,
            'info' => $info
        ]);
    }

}